package com.sqrj.phoneorder.Controller;

import com.sqrj.phoneorder.common.JsonData;
import com.sqrj.phoneorder.common.JsonUtils;
import com.sqrj.phoneorder.model.WebUserControl;
import com.sqrj.phoneorder.service.WebUserControlService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class WebUserControlController {

    @Resource
    private WebUserControlService webUserControlService;

    //查询单位
    @PostMapping("/queryUnit")
    public Map<String, Object> queryUnit(){
        Map<String, Object> modelMap = new HashMap<String, Object>();
        List<WebUserControl> unitList =   webUserControlService.queryUnit();
        modelMap.put("unitList", unitList);
        return modelMap;
    }

    //根据地址查询搅拌站
    @PostMapping("/queryUnitByAddr")
    public Map<String, Object> queryUnitByAddr(String address){
       String district;
        Map<String, Object> modelMap = new HashMap<String, Object>();
        String[] addr = address.split("-");
        String province = addr[0];
        String city = addr[1];
        if(addr[2].equals("全部")){
          district = null;
        }
        else{
          district = addr[2];}
        int lx = Integer.valueOf( addr[3]);
        List<WebUserControl> unitList =   webUserControlService.queryUnitByAddr(province,city,district,lx);
        modelMap.put("unitList", unitList);
        return modelMap;
    }

    //根据搅拌站code查询搅拌站信息
    @PostMapping("/getWebUserbyjbzCode")
    public JsonData getWebUserbyjbzCode(@RequestBody Map<String,Object> map){
        String jbzCode = (String)map.get("jbzCode");
        WebUserControl webUserControl =  webUserControlService.getWebUserbyjbzCode(jbzCode);
        return JsonData.success(webUserControl);
    }


}
